package health.lm.com.shop.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.jakewharton.rxbinding2.view.RxView;
import com.lm.sjy.titlebar.widget.CommonTitleBar;

import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import health.lm.com.component_base.base.mvp.activity.XActivity;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.router.ARouterConstant;
import health.lm.com.shop.R;
import health.lm.com.shop.R2;
import health.lm.com.shop.model.MallModel;
import health.lm.com.shop.presenter.PeopleDiscoverPresenter;
import health.lm.com.shop.widget.CircleMenuLayout;

import static health.lm.com.router.ARouterConstant.FROM_TYPE_INFLUENCE_TEAM;

/**
 * Created by Android Studio .
 * Project：hlian health.lm.com.shop.activity
 * Date：2019/8/16 10:35
 * Introduce：人脉发掘
 */
@Route(path = ARouterConstant.PeopleDiscoverActivity)
public class PeopleDiscoverActivity extends XActivity<PeopleDiscoverPresenter> {
    @BindView(R2.id.title_bar)
    CommonTitleBar mTitleBar;
    @BindView(R2.id.id_menulayout)
    CircleMenuLayout mIdMenulayout;
    @BindView(R2.id.iv_center)
    ImageView mIvCenter;
    @BindView(R2.id.id_circle_menu_item_center)
    RelativeLayout mIdCircleMenuItemCenter;
    @BindView(R2.id.textView67)
    TextView mTextView67;

    private List<String> idList;
    private List<String> realNameList;

    @Override
    public int getLayoutId() {
        return R.layout.hl_activity_people_discover;
    }

    @Override
    public PeopleDiscoverPresenter newP() {
        return new PeopleDiscoverPresenter();
    }

    @SuppressLint("CheckResult")
    @Override
    public void initData(Bundle savedInstanceState) {
        mTitleBar.setListener((v, action, extra) -> {
            switch (action) {
                case CommonTitleBar.ACTION_LEFT_BUTTON:
                    finish();
                    break;
                case CommonTitleBar.ACTION_RIGHT_TEXT:
                    ARouter.getInstance().build(ARouterConstant.HLPeopleActivity)
                            .withInt("from_type",FROM_TYPE_INFLUENCE_TEAM)
                            .navigation();
                    break;
            }
        });

        mIdMenulayout.setOnMenuItemClickListener(new CircleMenuLayout.OnMenuItemClickListener() {
            @Override
            public void itemClick(View view, int pos) {
                //RxToast.normal(names.get(pos));
                if (null == idList || null == realNameList) return;
                ARouter.getInstance().build(ARouterConstant.HLPeopleDetailActivity)
                        .withString("id", idList.get(pos))
                        .withString("name", realNameList.get(pos))
                        .navigation();
            }

            @Override
            public void itemCenterClick(View view) {
                getP().getData();
            }
        });

        //mIvCenter.setOnClickListener(v -> getP().getData());
        mTextView67.setVisibility(View.GONE);
        RxView.clicks(mTextView67).throttleFirst(2, TimeUnit.SECONDS).subscribe(v -> attention());
        getP().getData();
    }

    public void setNewData(List<String> ids, List<String> real_names, List<String> images, List<String> names, List<String> tags) {
        this.idList = ids;
        this.realNameList = real_names;
        mIdMenulayout.setMenuItemIconsAndTexts(images, names, real_names);
        mIdMenulayout.autoPlay();
        if (ids.size() <= 0) mTextView67.setVisibility(View.GONE);
        else mTextView67.setVisibility(View.VISIBLE);
    }

    private void attention() {
        MallModel.getInstance().attention(idList, 1, new SimpleCallBack<Object>() {
            @Override
            public void onSuccess(Object pO) {
                getP().getData();
            }
        });
    }
}
